package edu.cs.cs160.storytime;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class StoryBook {
	ArrayList<StoryPage> bookPages;
	private int cover;
	private int back;
	private int pageHeight; 
	private int pageWidth;
	private String name;
	private String author;
	private int curPage;
	private int bookID;
	private int numPages;
	private int libCover;

    public StoryBook(String n,String a,int cover, int backpage,int libraryCover) {
		this.name = n;
		this.author = a;
		this.bookPages = new ArrayList<StoryPage>();
		this.cover = cover;
		this.back = backpage;
        this.curPage = 0;
        this.numPages = 0;
        this.libCover = libraryCover;
	}
	
	public void addPage(StoryPage page) {
		this.bookPages.add(page);
		page.setID(numPages);
		numPages++;
	}
	
	public void setID(int id) {
		this.bookID = id;
	}
	
	public int getID() {
		return this.bookID;
	}
	
	public String getName() {
		return this.name;
	}
	public String getAuthor() {
		return this.author;
	}
	public void setDimensions(int pageHeight, int pageWidth) {
		this.pageHeight = pageHeight;
		this.pageWidth = pageWidth;
	}
	
	public StoryPage getPage(int pageID) {
		if (0 <= pageID && pageID < this.bookPages.size()) {
			return this.bookPages.get(pageID);
		} else {
			return StoryTime.library.getBlankPage();
		}
	}

	public StoryPage getCurPageOffset(int offset) {
		return this.getPage(this.curPage+offset);
	}	
	
	public StoryPage getCurPage() {
		return this.getPage(this.curPage);
	}
	
	public StoryPage getLeftPage() {
		return this.getCurPageOffset(1);
	}
	
	public StoryPage getRightPage() {
		return this.getCurPageOffset(2);
	}
	
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
	
	public int navigationStatus() {
		if (this.curPage+3 > this.bookPages.size()) {
			return 1;
		} else if (this.curPage-1 < 0) {
			return -1;	
		} else {
			return 0;
		}
	}
	
	public StoryPage nextPage() {
		if (this.curPage+2 >= this.bookPages.size()) {
			return StoryTime.library.getBlankPage();
		} else {
			this.setCurPage(curPage+2);
			return this.bookPages.get(this.curPage);
		}
	}
	
	public StoryPage prevPage() {
		if (this.curPage-2 < 0) {
			return StoryTime.library.getBlankPage();
		} else {
			this.setCurPage(curPage-2);
			return this.bookPages.get(this.curPage);
		}
	}
	
	public int getCover() {
		return this.cover;
	}

	public int getBack() {
		return this.back;
	}
	public int getLibraryCover() {
		return this.libCover;
	}
	public int getPageHeight() {
		return pageHeight;
	}
	public int getPageWidth() {
		return pageWidth;
	}
	public int getNumPages()
	{
		return this.bookPages.size();
	}
}

